package com.pdsu.graduation_design.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.pdsu.graduation_design.R;
import com.pdsu.graduation_design.dto.PayCommodityDTO;
import com.pdsu.graduation_design.dto.Store;
import com.pdsu.graduation_design.listener.PayListStoreListener;

import java.util.List;
import java.util.Map;

public class PayListViewAdapter extends BaseAdapter {


    private Context context;
    private TextView storeTitle;
    private ListView listViewItemListView;
    private TextView all_pr;
    private Map<Integer,List<PayCommodityDTO>> payCommodityDTOListsMaps ;
    private List<Store> storesList;

    public PayListViewAdapter(Context context, TextView all_pr, Map<Integer, List<PayCommodityDTO>> payCommodityDTOListsMaps, List<Store> storesList) {
        this.context = context;
        this.all_pr = all_pr;
        this.payCommodityDTOListsMaps = payCommodityDTOListsMaps;
        this.storesList = storesList;
    }
    private PayListViewItemListViewAdapter payListViewItemListViewAdapter;

    @Override
    public int getCount() {
        return storesList.size();
    }
    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


        View view=View.inflate(context, R.layout.fragment_pay_listview_item,null);
//        checkBox_store=view.findViewById(R.id.pay_store_checkbox);
        //点击进入店铺,传入店铺id
        TextView store_id = view.findViewById(R.id.pay_store_id);
        String storeID=store_id.getText().toString();
        storeTitle=view.findViewById(R.id.pay_store_title_textview);
        storeTitle.setText(storesList.get(position).getUsername());
//---------------------------------------------------------------------------------------------
        storeTitle.setOnClickListener(new PayListStoreListener(context,storesList.get(position).getUid()));
//---------------------------------------------------------------------------------------------
        //每一项均为一个listview 给listview设置adapter
//        listViewItemListView= view.findViewById(R.id.pay_listview_itemlistview);
        PayListViewItemListViewAdapter payListViewItemListViewAdapter=new PayListViewItemListViewAdapter(context,payCommodityDTOListsMaps.get(storesList.get(position).getUid()),all_pr);
        listViewItemListView.setAdapter(payListViewItemListViewAdapter);
        listViewItemListView.requestLayout();
        payListViewItemListViewAdapter.notifyDataSetChanged();

        return view;
    }

    private void setItemAdapter(int uid){
        //将店的id传入


//        listViewItemListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                Toast.makeText(context, "点击了"+position, Toast.LENGTH_SHORT).show();
//            }
//        });

//        checkBox_store.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                if (buttonView.isChecked()){
//
//                    for (int i=0;i<payCommodityLists.size();i++){
//
//                        if (!payCommodityLists.get(i).getBo()){
//
//                            payCommodityLists.get(i).setBo(true);
//                            System.out.println("选中"+i);
//
//                        }
//                    }
//
//                }else {
//
//                    for (int i=0;i<payCommodityLists.size();i++){
//                        if (payCommodityLists.get(i).getBo()){
//                            payCommodityLists.get(i).setBo(false);
//                            System.out.println("取消选中"+i);
//                        }
//                    }
//                }
//
//                listViewItemListView.setAdapter(new PayListViewItemListViewAdapter(context,payCommodityLists,all_pr) );
//            }
//
//
//        });




    }
}
